<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../css/style.css">
    <script src="../plugins/echarts/echarts.js"></script>
    <!--element日期所需-->
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <link rel="stylesheet" href="../plugins/elementui/index.css">
</head>
<body class="hold-transition">
<!--日期控件-->
<div id="date">
    <template>
        <div class="block">
            <br><span>请选择日期区间</span>
            <el-date-picker
                    v-model="value"
                    type="daterange"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    :default-time="['00:00:00', '23:59:59']"
                    @blur="findData()">
            </el-date-picker>
        </div>
    </template>
</div>


<div id="app">
    <div class="content-header">
        <h1>收入统计</h1>
    </div>
    <div class="app-container">
        <div class="box">
            <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
            <div id="chart1" style="height:600px;"></div>
        </div>
    </div>
</div>
</body>

<script src="../js/axios-0.18.0.js"></script>
<script>        var vue = new Vue({
    el: "#date", data: {value: ''}, created() {
        var date1 = new Date(), end = date1.getFullYear() + "-" + (date1.getMonth() + 1) + "-" + date1.getDate();
        var date2 = new Date(date1);
        date2.setDate(date1.getDate() - 7);
        var begin = date2.getFullYear() + "-" + (date2.getMonth() + 1) + "-" + date2.getDate();
        this.sendAndGet(begin, end)
    }, methods: {
        findData() {
            var beginDate = this.value[0];
            var begin = beginDate.getFullYear() + "-" + (beginDate.getMonth() + 1) + "-" + beginDate.getDate();
            var endDate = this.value[1];
            var end = endDate.getFullYear() + "-" + (endDate.getMonth() + 1) + "-" + endDate.getDate();
            this.sendAndGet(begin, end)
        }, sendAndGet(begin, end) {
            var myChart = echarts.init(document.getElementById('chart1'));
            axios.get("/report/income.do?begin=" + begin + "&end=" + end).then((res) => {
                if (res.data.flag) {
                    myChart.setOption({
                        tooltip: {trigger: 'item', formatter: '{a} <br/>{b}: {c} ({d}%)'},
                        legend: {orient: 'vertical', left: 10, data: res.data.data.setMeals},
                        series: [{
                            name: '访问来源',
                            type: 'pie',
                            radius: ['50%', '70%'],
                            avoidLabelOverlap: false,
                            label: {show: false, position: 'center'},
                            emphasis: {label: {show: true, fontSize: '30', fontWeight: 'bold'}},
                            labelLine: {show: false},
                            data: res.data.data.income
                        }]
                    });
                } else {
                    this.$message.error("此日期范围内无到诊人员")
                }
            });
        }
    }
})    </script>

</html>